// var urlBox = 'http://192.168.7.41:8000';
// 移入移出 上下banner图
$(".carousel").mouseenter(function () {
	$('.carousel-control').fadeIn();
});
$(".carousel").mouseleave(function () {
    $('.carousel-control').fadeOut();
});


// 页面加载显示
$(function() {
	//获取首页banner
	HomeBanner();

	//获取首页企业动态
	business_movement();
	
	//获取微信公众号文章链接
	WechatArticle();
	
	//获取服务类目
	ServiceCategory();
})

//获取首页banner
function HomeBanner() {
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/website/HomeBanner/',
		dataType: 'json',
		success: function(data) {
			var case_list = data.banner_list;
			for (var i = 0; i < case_list.length; i++) {
				// console.log(case_list[i].banner_img)
				var divs = $('<div class="item">'+
					'<img class="hidden-xs" src="'+urlBox+case_list[i].banner_img+'" alt="...">'+
					'<img class="visible-xs-block" src="'+urlBox+case_list[i].banner_img+'" alt="">'+
				'</div>')
				var li = $('<li data-target="#carousel-example-generic" data-slide-to="1"></li>')
				$(".carousel-inner").append(divs);
				$(".carousel-indicators").append(li);
			}
			$('.carousel-inner>div').eq(0).addClass('active')
			$('.carousel-indicators>li').eq(0).addClass('active')
		}
	})
}

//获取首页企业动态
function business_movement() {
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/website/HomeMovement/',
		dataType: 'json',
		success: function(data) {
			var case_list = data.movement_list;
			var div = $('<div class="hidden-xs movementTitle" movement_id='+case_list[0].id+'>'+
					'<img src="'+urlBox+case_list[0].article_banner+'" alt="">'+
					'<div>'+
						'<div>'+case_list[0].title+' </div>'+
						'<span>'+case_list[0].create_time+'</span>'+
						'<p>'+case_list[0].movement_intro+'</p>'+
					'</div>'+
				'</div>')
			$(".dynamic").prepend(div);
			var divs = ''
			for (var i = 0; i < case_list.length; i++) {
				if(i == 0){   
					divs+=`
					<li class="visible-xs-block visible-sm-block" movement_id='${case_list[i].id}'>
					`
				}else{
					divs+=`
					<li movement_id='${case_list[i].id}'>
					`
				}				
				divs+=`
					<img src="${urlBox+case_list[i].article_banner}" alt="" class="visible-xs-block">
					<div>
						<div>${case_list[i].title}<span class="hidden-xs">${case_list[i].create_time}</span></div>
						<span class="visible-xs-block">${case_list[i].create_time}</span>
						<p>${case_list[i].movement_intro}</p>
					</div>
				</li>
				`
			}	
				// var divs = $('<li movement_id='+case_list[i].id+'>'+
				// 	// '<img src="images/pc/home/home_dynamics_img01.png" alt="">'+
				// 	'<img src="'+urlBox+case_list[i].article_banner+'" alt="" class="visible-xs-block">'+
				// 	'<div>'+
				// 		'<div>'+case_list[i].title+'<span class="hidden-xs">'+case_list[i].create_time+'</span></div>'+
				// 		'<span class="visible-xs-block">'+case_list[i].create_time+'</span>'+
				// 		'<p>'+case_list[i].movement_intro+'</p>'+
				// 	'</div>'+
				// '</li>')
				$(".dynamic .business_movement").append(divs);
				
			
			
			
			$('.business_movement li').click(function() {
				var movement_id = $(this).attr("movement_id")
				window.location.replace("dynamic_details.html?movement_id="+movement_id);
			})
			$('.movementTitle').click(function() {
				var movement_id = $(this).attr("movement_id")
				window.location.replace("dynamic_details.html?movement_id="+movement_id);
			})
		}
	})
}

//获取微信公众号文章链接
function WechatArticle() {
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/website/WechatArticle/',
		dataType: 'json',
		success: function(data) {
			// console.log(data)
			var case_list = data.article_list;
			for (var i = 0; i < case_list.length; i++) {
				var divs = $('<li>'+
					'<a href="'+case_list[i].article_url+'">'+
						'<img src="'+urlBox+case_list[i].background_image+'" alt="">'+
						'<p>'+case_list[i].title+'</p>'+
						'<div>'+
							'<div>微信阅读量</div>'+
							'<span>'+case_list[i].pviews+'</span>'+
						'</div>'+
					'</a>'+
				'</li>')
				$(".WechatArticle").append(divs);
			}
		}
	})
}

//获取服务品类
function ServiceCategory() {
	$.ajax({ 
		type: 'GET',
		url: urlBox+'/api/website/ServiceCategory/',
		dataType: 'json',
		success: function(data) {
			// console.log(data)
			var case_list = data.category_list;
			for (var i = 0; i < case_list.length; i++) {
				var divs = $('<li>'+
					'<img src="'+urlBox+case_list[i].service_icon+'" alt="">'+
					// '<img src="images/pc/home/home_category_light.png" alt="">'+
					'<div>'+
						'<div>'+case_list[i].service_name+'</div>'+
						'<p class="visible-lg-block visible-md-block">'+case_list[i].service_intro+'</p>'+
					'</div>'+
				'</li>')
				$(".category ul").append(divs);
			}
		}
	})
}





